import { _decorator, Component, EventKeyboard, input, Input, KeyCode, macro, ResolutionPolicy, view, } from 'cc';
const { ccclass, property } = _decorator;

import SS_GameManager from "./SS_GameManager";
import WaitingPanel from '../UI/WaitingPanel';
import SS_UIManager from './SS_UIManager';
import { SS_AudioManager } from './SS_AudioManager';
import CardFunctions from '../Common/CardFunctions';
import { GameItem } from '../Data/GameEnum';

@ccclass('SS_InputManager')
export default class SS_InputManager extends Component {
        static Instance: SS_InputManager;

        onLoad() {
                SS_InputManager.Instance = this;

                input.on(Input.EventType.KEY_DOWN, this.onKeyDown, this);
                input.on(Input.EventType.KEY_UP, this.onKeyUp, this);
        }

        async onKeyDown(event: EventKeyboard) {
                if (event.keyCode == KeyCode.ARROW_UP || event.keyCode == KeyCode.KEY_W) {
                        console.log(`up`);
                        SS_GameManager.Instance.上一关();
                }
                if (event.keyCode == KeyCode.ARROW_DOWN || event.keyCode == KeyCode.KEY_S) {
                        console.log(`down`);
                        SS_GameManager.Instance.下一关();
                }
                if (event.keyCode == KeyCode.ARROW_LEFT || event.keyCode == KeyCode.KEY_A) {
                        console.log(`left`);
                        SS_GameManager.Instance.上一关();
                }
                if (event.keyCode == KeyCode.ARROW_RIGHT || event.keyCode == KeyCode.KEY_D) {
                        console.log(`right`);
                        SS_GameManager.Instance.下一关();
                }

                if (event.keyCode == KeyCode.SPACE) {
                        console.log(`空格`);

                        console.log(GameItem);

                        var keys = Object.keys(GameItem)
                        console.log(keys);

                        // SS_UIManager.Instance.CreatePanel(`UI/WaitingPanel`, WaitingPanel);

                        // CardFunctions.连击();
                        // localStorage.clear();
                }

                if (event.keyCode == KeyCode.ESCAPE) {
                }

                if (event.keyCode == KeyCode.NUM_1) {
                        console.log("num1");
                        // SS_GameManager.Instance.成功()
                        view.setDesignResolutionSize(720, 1600, ResolutionPolicy.FIXED_HEIGHT)
                        view.emit("canvas-resize")

                }
                if (event.keyCode == KeyCode.NUM_2) {
                        console.log("num2");
                        // SS_GameManager.Instance.失败()
                        view.setDesignResolutionSize(720, 1600, ResolutionPolicy.FIXED_WIDTH)
                        view.emit("canvas-resize")

                }

                if (event.keyCode == KeyCode.NUM_3) {
                        console.log("num3");

                        // SS_AudioManager.Instance.pause();
                        view.setDesignResolutionSize(720, 1600, ResolutionPolicy.SHOW_ALL)
                        view.emit("canvas-resize")

                }

                if (event.keyCode == KeyCode.NUM_4) {
                        console.log("num4");

                        // SS_AudioManager.Instance.resume();
                        view.setDesignResolutionSize(720, 1600, ResolutionPolicy.NO_BORDER)
                        view.emit("canvas-resize")

                }

                if (event.keyCode == KeyCode.NUM_5) {
                        console.log("num5");

                        CardFunctions.PlayGuide_2();
                }

                if (event.keyCode == KeyCode.NUM_6) {
                        console.log("num6");

                        CardFunctions.StopGuide_2();
                }

        }

        onKeyUp(event: EventKeyboard) { }
}